package com.thirdgroup.dao.impl;

import com.thirdgroup.dao.CusInfoDao;
import com.thirdgroup.dao.base.BaseDAO;
import com.thirdgroup.pojo.entity.CustomerInfo;

import java.util.List;

public class CusInfoDaoImpl extends BaseDAO<CustomerInfo> implements CusInfoDao {
    @Override
    public List<CustomerInfo> selectAll() {
        String sql=" select * from customer_info order by customerID desc";
        return findAll(sql,null);
    }

    @Override
    public Integer updateState(String id, String status ,String date) {
        String sql="update customer_info set customerStatus=? , updateTime=? where customerID=? ";
        Object[] params={status,date,id};
        return executeSQL(sql,params);
    }

    @Override
    public Integer delete(String customerId) {
        String sql="delete from customer_info where customerID=?";
        Object[] params={customerId};
        return executeSQL(sql,params);
    }

    @Override
    public CustomerInfo detail(String customerId) {
        String sql="select * from customer_info where customerID=?";
        Object[] params={customerId};
        return findOne(sql,params);
    }

    @Override
    public Integer add(String id, String username, String encrypt, String name,  Integer industry, String formattedDate, String profilePicture) {
        String sql=" insert into customer_info(customerID,customerUserName,customerPassword,customerName,customerBalance,customerStatus,customerIndustryID,createTime,updateTime,profilePicture)\n" +
                " values(?,?,?,?,0,'使用中',?,?,?,?)";
        Object[] params={id,username,encrypt,name,industry,formattedDate,formattedDate,profilePicture};
        return executeSQL(sql,params);
    }

    @Override
    public Integer updateBalance(String customerID, Double total) {
        String sql="update customer_info set customerBalance=customerBalance-? where customerID=?";
        Object[] params={total,customerID};
        return super.executeSQL(sql,params);
    }
}
